package com.wowangz.cms.systemmanage.exportreport.api;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Workbook;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wowangz.cms.common.utils.DataFormat;
import com.wowangz.cms.common.utils.SysConstant;
import com.wowangz.cms.component.datagrid.pojo.DataGrid;
import com.wowangz.cms.component.datagrid.pojo.DataResult;
import com.wowangz.cms.component.datagrid.pojo.DataStyle;
import com.wowangz.cms.component.datagrid.pojo.PangingParam;
import com.wowangz.cms.component.datagrid.utils.DataTypeConstant;
import com.wowangz.cms.component.datagrid.utils.PangingTools;
import com.wowangz.cms.syscore.IssTransactionContainer;
import com.wowangz.cms.syscore.api.BaseController;
import com.wowangz.cms.syscore.api.JSONFactory;
import com.wowangz.cms.syscore.utils.ServletUtils;
import com.wowangz.cms.systemmanage.exportreport.entity.BuyRecord;
import com.wowangz.cms.systemmanage.exportreport.entity.CallRecord;
import com.wowangz.cms.systemmanage.exportreport.entity.PreferentialRecord;
import com.wowangz.cms.systemmanage.exportreport.entity.TapesRecord;
import com.wowangz.cms.systemmanage.exportreport.entity.TranslatorOnOff;
import com.wowangz.cms.systemmanage.exportreport.entity.TranslatorOnline;
import com.wowangz.cms.systemmanage.exportreport.entity.TranslatorOrder;
import com.wowangz.cms.systemmanage.exportreport.entity.TranslatorRecord;
import com.wowangz.cms.systemmanage.exportreport.entity.UnpaiedPackageRecord;
import com.wowangz.cms.systemmanage.exportreport.service.ExportReportService;

import net.sf.jxls.transformer.XLSTransformer;


@Scope("prototype")
@Controller
public class ExportReportController extends BaseController{

	private static Logger logger = LoggerFactory.getLogger(ExportReportController.class);
	
	/**
	 * 
	 * @Title: queryReportList 
	 * @Description: 点击菜单"用户叫单"显示“用户叫单”列表
	 * @return String
	 * @author Green.Long
	 * @date 2016年8月14日 下午11:28:35
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryCallRecordList.web")
	public String queryCallRecordList(HttpServletRequest request, HttpServletResponse response, Model model) {
		//获取时间段
		String startTime = DataFormat.formatDate(DataFormat.getPreQueryDatebox(new Date()), DataFormat.DT_YYYY_MM_DD);
		String endTime = DataFormat.formatDate(DataFormat.getNowDay(new Date()), DataFormat.DT_YYYY_MM_DD);
		model.addAttribute("startTime", startTime);
		model.addAttribute("endTime", endTime);

		return "/WEB-INF/jsp/systemmanage/exportreport/callRecordList";
	}
	
	/**
	 * 
	 * @Title: queryReportListInfoDataGrid 
	 * @Description: 打开“用户叫单”列表加载列表数据
	 * @return void
	 * @author Green.Long
	 * @date 2016年8月14日 下午11:28:27
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryCallRecordInfoDataGrid.json")
	public void queryReportListInfoDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());

			ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
			long resultCount = exportReportService.findCallRecordCount(map);
			List<CallRecord> resultList = exportReportService.findCallRecordList(map);

			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("nickName", DataTypeConstant.STRING);
			dataStyle.addDepict("udid", DataTypeConstant.STRING);
			dataStyle.addDepict("locale", DataTypeConstant.STRING);
			dataStyle.addDepict("phone", DataTypeConstant.STRING);
			dataStyle.addDepict("email", DataTypeConstant.STRING);
			dataStyle.addDepict("registerTime", DataTypeConstant.STRING);
			dataStyle.addDepict("sourceLang", DataTypeConstant.STRING);
			dataStyle.addDepict("tarLang", DataTypeConstant.STRING);
			dataStyle.addDepict("translatorId", DataTypeConstant.STRING);
			dataStyle.addDepict("translatorNickName", DataTypeConstant.STRING);
			dataStyle.addDepict("translatorPhone", DataTypeConstant.STRING);
			dataStyle.addDepict("translatorMontherTongue", DataTypeConstant.STRING);
			dataStyle.addDepict("translatorAbilityTongue", DataTypeConstant.STRING);
			dataStyle.addDepict("translatorType", DataTypeConstant.STRING);
			dataStyle.addDepict("starLevel", DataTypeConstant.STRING);
			dataStyle.addDepict("evaluateContent", DataTypeConstant.STRING);
			dataStyle.addDepict("serviceType", DataTypeConstant.STRING);
			dataStyle.addDepict("serviceResult", DataTypeConstant.STRING);
			dataStyle.addDepict("callTime", DataTypeConstant.STRING);
			dataStyle.addDepict("serviceStartTime", DataTypeConstant.STRING);
			dataStyle.addDepict("serviceEndTime", DataTypeConstant.STRING);
			dataStyle.addDepict("serviceTime", DataTypeConstant.LONG);
			dataStyle.addDepict("cancelCallTime", DataTypeConstant.STRING);
			dataStyle.addDepict("permissionTime", DataTypeConstant.LONG);
			dataStyle.addDepict("userTime", DataTypeConstant.LONG);
			dataStyle.addDepict("postPaiedTime", DataTypeConstant.LONG);			
			dataStyle.addDepict("payType", DataTypeConstant.STRING);
			dataStyle.addDepict("payResult", DataTypeConstant.STRING);
			dataStyle.addDepict("payMoney", DataTypeConstant.STRING);			
			dataStyle.addDepict("userId", DataTypeConstant.STRING);
			dataStyle.addDepict("flowId", DataTypeConstant.STRING);
			
			dataStyle.addDepict("linkType", DataTypeConstant.STRING);
			dataStyle.addDepict("chatDuration", DataTypeConstant.STRING);
			dataStyle.addDepict("voiceDuration", DataTypeConstant.STRING);
			dataStyle.addDepict("duration", DataTypeConstant.STRING);
			dataStyle.addDepict("agoraChannelId", DataTypeConstant.STRING);
					
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载用户叫单惠列表数据成功");
		} catch (Exception e) {
			logger.error("加载用户叫单列表数据失败",e);
			e.printStackTrace();
		}
	}
	
	
	
	/**
	 * 
	 * @Title: exportCallReport 
	 * @Description: 导出叫单数据
	 * @return void
	 * @author Green.Long
	 * @throws Exception 
	 * @date 2016年8月14日 下午11:28:18
	 */
	@RequestMapping(value = "/systemmanage/exportreport/exportCallReport.web")
    public void exportCallReport(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		HashMap<String, Object> map = new HashMap<String, Object>();
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
        List<CallRecord> list = exportReportService.listCallRecord(map);
        if (null != list && !list.isEmpty()) {
            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/callrecord_template.xlsx").getPath();
            String destFileName = String.format("叫单报表_%s.xlsx", new DateTime().toString("yyyyMMddHHmmss"));
            Map<String, List<CallRecord>> beanParams = new HashMap<String, List<CallRecord>>();
            beanParams.put("callRecordList", list);

            XLSTransformer transformer = new XLSTransformer();
            InputStream in = null;
            OutputStream out = null;
            // 设置响应
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
            response.setContentType("application/vnd.ms-excel");
            try {
                in = new BufferedInputStream(new FileInputStream(templateFileName));
                Workbook workbook = transformer.transformXLS(in, beanParams);
                out = response.getOutputStream();
                // 将内容写入输出流并把缓存的内容全部发出去
                workbook.write(out);
                out.flush();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                    }
                }
            }
        } else {
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write("暂无数据");
        }
    }
	
	
	
	
	/**
	 * 
	 * @Title: queryBuyReportList 
	 * @Description: 点击菜单"套餐购买记录"显示“套餐购买记录”列表
	 * @return String
	 * @author Green.Long
	 * @date 2016年8月15日 下午2:49:21
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryBuyRecordList.web")
	public String queryBuyReportList(HttpServletRequest request, HttpServletResponse response, Model model) {
		//获取时间段
		String startTime = DataFormat.formatDate(DataFormat.getPreQueryDatebox(new Date()), DataFormat.DT_YYYY_MM_DD);
		String endTime = DataFormat.formatDate(DataFormat.getNowDay(new Date()), DataFormat.DT_YYYY_MM_DD);
		model.addAttribute("startTime", startTime);
		model.addAttribute("endTime", endTime);
		return "/WEB-INF/jsp/systemmanage/exportreport/buyRecordList";
	}
	
	/**
	 * 
	 * @Title: queryBuyRecordInfoDataGrid 
	 * @Description:  打开“套餐购买记录”列表加载列表数据
	 * @return void
	 * @author Green.Long
	 * @date 2016年8月15日 下午2:49:58
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryBuyRecordInfoDataGrid.json")
	public void queryBuyRecordInfoDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());

			ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
			long resultCount = exportReportService.findBuyRecordCount(map);
			List<BuyRecord> resultList = exportReportService.findBuyRecordList(map);

			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("nickName", DataTypeConstant.STRING);
			dataStyle.addDepict("phone", DataTypeConstant.STRING);
			dataStyle.addDepict("email", DataTypeConstant.STRING);
			dataStyle.addDepict("packageName", DataTypeConstant.STRING);
			dataStyle.addDepict("payType", DataTypeConstant.STRING);
			dataStyle.addDepict("payMoney", DataTypeConstant.STRING);
			dataStyle.addDepict("buyTime", DataTypeConstant.STRING);	 
			dataStyle.addDepict("userId", DataTypeConstant.STRING);	
					
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载套餐购买记录列表数据成功");
		} catch (Exception e) {
			logger.error("加载套餐购买记录列表数据失败",e);
			e.printStackTrace();
		}
	}
	
	
	
	/**
	 * 
	 * @Title: exportCallReport 
	 * @Description: 导出叫单数据
	 * @return void
	 * @author Green.Long
	 * @throws Exception 
	 * @date 2016年8月14日 下午11:28:18
	 */
	@RequestMapping(value = "/systemmanage/exportreport/exportBuyReport.web")
    public void exportBuyReport(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		HashMap<String, Object> map = new HashMap<String, Object>();
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
        List<BuyRecord> list = exportReportService.listBuyRecord(map);
        if (null != list && !list.isEmpty()) {
            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/buyrecord_template.xlsx").getPath();
            String destFileName = String.format("套餐购买记录报表_%s.xlsx", new DateTime().toString("yyyyMMddHHmmss"));
            Map<String, List<BuyRecord>> beanParams = new HashMap<String, List<BuyRecord>>();
            beanParams.put("buyRecordList", list);

            XLSTransformer transformer = new XLSTransformer();
            InputStream in = null;
            OutputStream out = null;
            // 设置响应
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
            response.setContentType("application/vnd.ms-excel");
            try {
                in = new BufferedInputStream(new FileInputStream(templateFileName));
                Workbook workbook = transformer.transformXLS(in, beanParams);
                out = response.getOutputStream();
                // 将内容写入输出流并把缓存的内容全部发出去
                workbook.write(out);
                out.flush();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                    }
                }
            }
        } else {
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write("暂无数据");
        }
    }
	
	
	
	/**
	 * 
	 * @Title: queryTranslatorRecordList 
	 * @Description: 点击菜单"译员信息清单"显示“译员信息清单”列表
	 * @return String
	 * @author Green.Long
	 * @date 2016年8月15日 下午3:35:50
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryTranslatorRecordList.web")
	public String queryTranslatorRecordList(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		return "/WEB-INF/jsp/systemmanage/exportreport/translatorRecordList";
	}
	
	/**
	 * 
	 * @Title: queryTranslatorRecordInfoDataGrid 
	 * @Description: 打开“译员清单”列表加载列表数据
	 * @return void
	 * @author Green.Long
	 * @date 2016年8月15日 下午3:37:47
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryTranslatorRecordInfoDataGrid.json")
	public void queryTranslatorRecordInfoDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());

			ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
			long resultCount = exportReportService.findTranslatorRecordCount(map);
			List<TranslatorRecord> resultList = exportReportService.findTranslatorRecordList(map);

			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("translatorId", DataTypeConstant.STRING);
			dataStyle.addDepict("translatorName", DataTypeConstant.STRING);
			dataStyle.addDepict("createTime", DataTypeConstant.STRING);
			dataStyle.addDepictByFunction("dataStatus", SysConstant.TEDataStatus.class, "getName", new Class[] { String.class });
			dataStyle.addDepict("phone", DataTypeConstant.STRING);
			dataStyle.addDepictByFunction("translatorType", SysConstant.TranslatorType.class, "getName", new Class[] { String.class });
			dataStyle.addDepict("montherTongue", DataTypeConstant.STRING);	 
			dataStyle.addDepict("otherLanguage", DataTypeConstant.STRING);	
					
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载译员清单列表数据成功");
		} catch (Exception e) {
			logger.error("加载译员清单列表数据失败",e);
			e.printStackTrace();
		}
	}
	

	/**
	 * 
	 * @Title: exportTranslatorReport 
	 * @Description: 导出译员清单
	 * @return void
	 * @author Green.Long
	 * @date 2016年8月15日 下午3:41:09
	 */
	@RequestMapping(value = "/systemmanage/exportreport/exportTranslatorReport.web")
    public void exportTranslatorReport(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		HashMap<String, Object> map = new HashMap<String, Object>();
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
        List<TranslatorRecord> list = exportReportService.listTranslatorRecord(map);
        if (null != list && !list.isEmpty()) {
            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/translatorrecord_template.xlsx").getPath();
            String destFileName = String.format("译员信息清单报表_%s.xlsx", new DateTime().toString("yyyyMMddHHmmss"));
            Map<String, List<TranslatorRecord>> beanParams = new HashMap<String, List<TranslatorRecord>>();
            beanParams.put("translatorRecordList", list);

            XLSTransformer transformer = new XLSTransformer();
            InputStream in = null;
            OutputStream out = null;
            // 设置响应
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
            response.setContentType("application/vnd.ms-excel");
            try {
                in = new BufferedInputStream(new FileInputStream(templateFileName));
                Workbook workbook = transformer.transformXLS(in, beanParams);
                out = response.getOutputStream();
                // 将内容写入输出流并把缓存的内容全部发出去
                workbook.write(out);
                out.flush();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                    }
                }
            }
        } else {
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write("暂无数据");
        }
    }
	
	/**
	 * 
	 * @Title: queryUnpaiedPackageRecordList 
	 * @Description: 点击菜单"下单未购买"显示“下单未购买”列表
	 * @return String
	 * @author Green.Long
	 * @date 2016年8月15日 下午3:58:06
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryUnpaiedPackageRecordList.web")
	public String queryUnpaiedPackageRecordList(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		return "/WEB-INF/jsp/systemmanage/exportreport/unpaiedPackageRecordList";
	}
	
	/**
	 * 
	 * @Title: queryUnpaiedPackageRecordInfoDataGrid 
	 * @Description: 打开“下单未购买”列表加载列表数据
	 * @return void
	 * @author Green.Long
	 * @date 2016年8月15日 下午3:58:21
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryUnpaiedPackageRecordInfoDataGrid.json")
	public void queryUnpaiedPackageRecordInfoDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());

			ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
			long resultCount = exportReportService.findUnpaiedPackageRecordCount(map);
			List<UnpaiedPackageRecord> resultList = exportReportService.findUnpaiedPackageRecordList(map);

			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("nickName", DataTypeConstant.STRING);
			dataStyle.addDepict("phone", DataTypeConstant.STRING);
			dataStyle.addDepict("email", DataTypeConstant.STRING);
			dataStyle.addDepict("unpaiedMoney", DataTypeConstant.STRING);
			dataStyle.addDepict("orderTime", DataTypeConstant.STRING);
			dataStyle.addDepict("userId", DataTypeConstant.STRING);	 
			dataStyle.addDepict("orderId", DataTypeConstant.STRING);
					
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载下单未购买列表数据成功");
		} catch (Exception e) {
			logger.error("加载下单未购买列表数据失败",e);
			e.printStackTrace();
		}
	}
	

	/**
	 * 
	 * @Title: exportUnpaiedPackageReport 
	 * @Description: 导出下单未购买
	 * @return void
	 * @author Green.Long
	 * @date 2016年8月15日 下午3:58:56
	 */
	@RequestMapping(value = "/systemmanage/exportreport/exportUnpaiedPackageReport.web")
    public void exportUnpaiedPackageReport(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		HashMap<String, Object> map = new HashMap<String, Object>();
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
        List<UnpaiedPackageRecord> list = exportReportService.listUnpaiedPackageRecord(map);
        if (null != list && !list.isEmpty()) {
            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/unpaiedpackagerecord_template.xlsx").getPath();
            String destFileName = String.format("下单未购买报表_%s.xlsx", new DateTime().toString("yyyyMMddHHmmss"));
            Map<String, List<UnpaiedPackageRecord>> beanParams = new HashMap<String, List<UnpaiedPackageRecord>>();
            beanParams.put("unpaiedPackageRecordList", list);

            XLSTransformer transformer = new XLSTransformer();
            InputStream in = null;
            OutputStream out = null;
            // 设置响应
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
            response.setContentType("application/vnd.ms-excel");
            try {
                in = new BufferedInputStream(new FileInputStream(templateFileName));
                Workbook workbook = transformer.transformXLS(in, beanParams);
                out = response.getOutputStream();
                // 将内容写入输出流并把缓存的内容全部发出去
                workbook.write(out);
                out.flush();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                    }
                }
            }
        } else {
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write("暂无数据");
        }
    }
	
	/**
	 * 
	 * @Title: queryPreferentialRecordList 
	 * @Description: 点击菜单"优惠码使用情况"显示“优惠码使用情况”列表
	 * @return String
	 * @author Green.Long
	 * @date 2016年8月15日 下午4:26:48
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryPreferentialRecordList.web")
	public String queryPreferentialRecordList(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		return "/WEB-INF/jsp/systemmanage/exportreport/preferentialRecordList";
	}
	
	/**
	 * 
	 * @Title: queryPreferentialRecordInfoDataGrid 
	 * @Description: 打开“优惠码使用情况”列表加载列表数据
	 * @return void
	 * @author Green.Long
	 * @date 2016年8月15日 下午4:26:34
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryPreferentialRecordInfoDataGrid.json")
	public void queryPreferentialRecordInfoDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());

			ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
			long resultCount = exportReportService.findPreferentialRecordCount(map);
			List<PreferentialRecord> resultList = exportReportService.findPreferentialRecordList(map);

			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("code", DataTypeConstant.STRING);
			dataStyle.addDepict("dataStatus", DataTypeConstant.STRING);
			dataStyle.addDepict("usedTime", DataTypeConstant.STRING);
			dataStyle.addDepict("preferentialType", DataTypeConstant.STRING);
			dataStyle.addDepict("preferentialTimes", DataTypeConstant.STRING);
			dataStyle.addDepict("medium", DataTypeConstant.STRING);	 
			dataStyle.addDepict("channel", DataTypeConstant.STRING);
			dataStyle.addDepict("creater", DataTypeConstant.STRING);
			dataStyle.addDepict("createTime", DataTypeConstant.STRING);
			dataStyle.addDepict("phone", DataTypeConstant.STRING);
			dataStyle.addDepict("email", DataTypeConstant.STRING);
			dataStyle.addDepict("userId", DataTypeConstant.STRING);
			dataStyle.addDepict("nickName", DataTypeConstant.STRING);
					
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载优惠码使用情况列表数据成功");
		} catch (Exception e) {
			logger.error("加载优惠码使用情况列表数据失败",e);
			e.printStackTrace();			
		}
	}
	

	/**
	 * 
	 * @Title: exportPreferentialReport 
	 * @Description: 导出优惠码使用情况
	 * @return void
	 * @author Green.Long
	 * @date 2016年8月15日 下午4:26:16
	 */
	@RequestMapping(value = "/systemmanage/exportreport/exportPreferentialReport.web")
    public void exportPreferentialReport(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		HashMap<String, Object> map = new HashMap<String, Object>();
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
        List<PreferentialRecord> list = exportReportService.listPreferentialRecord(map);
        if (null != list && !list.isEmpty()) {
            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/preferentialrecord_template.xlsx").getPath();
            String destFileName = String.format("优惠码使用情况报表_%s.xlsx", new DateTime().toString("yyyyMMddHHmmss"));
            Map<String, List<PreferentialRecord>> beanParams = new HashMap<String, List<PreferentialRecord>>();
            beanParams.put("preferentialRecordList", list);

            XLSTransformer transformer = new XLSTransformer();
            InputStream in = null;
            OutputStream out = null;
            // 设置响应
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
            response.setContentType("application/vnd.ms-excel");
            try {
                in = new BufferedInputStream(new FileInputStream(templateFileName));
                Workbook workbook = transformer.transformXLS(in, beanParams);
                out = response.getOutputStream();
                // 将内容写入输出流并把缓存的内容全部发出去
                workbook.write(out);
                out.flush();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                    }
                }
            }
        } else {
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write("暂无数据");
        }
    }
	
	/**
	 * 查询录音列表
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryTapesList.web")
	public String queryTapesList(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		return "/WEB-INF/jsp/systemmanage/exportreport/tapesList";
	}
	
	@RequestMapping(value = "/systemmanage/exportreport/queryTapesRecordInfoDataGrid.json")
	public void queryTapesRecordInfoDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());

			ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
			long resultCount = exportReportService.listTapesRecordCount(map);
			List<TapesRecord> resultList = exportReportService.listTapesRecord(map);

			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("flow_id", DataTypeConstant.STRING);
			dataStyle.addDepict("create_time", DataTypeConstant.STRING);
			dataStyle.addDepict("datestr", DataTypeConstant.STRING);
			dataStyle.addDepict("filename", DataTypeConstant.STRING);
			dataStyle.addDepict("translatorId",DataTypeConstant.STRING);
			dataStyle.addDepict("translatorName", DataTypeConstant.STRING);
			dataStyle.addDepict("teUid", DataTypeConstant.STRING);	 
			dataStyle.addDepict("tenickname", DataTypeConstant.STRING);	
			dataStyle.addDepict("count", DataTypeConstant.STRING);
			dataStyle.addDepict("channelid", DataTypeConstant.STRING);
			dataStyle.addDepict("regtime", DataTypeConstant.STRING);
			dataStyle.addDepict("udid", DataTypeConstant.STRING);
			dataStyle.addDepict("severduration", DataTypeConstant.STRING);
					
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载录音清单列表数据成功");
		} catch (Exception e) {
			logger.error("加载录音清单列表数据失败",e);
			e.printStackTrace();
		}
	}
	
	/**
	 * 导出录音数据
	 * @param request
	 * @param response
	 * @param model
	 */
	@RequestMapping(value = "/systemmanage/exportreport/exportTapesRecord.web")
	public void exportTapesRecord(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		try {
				HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
		        String startTime = request.getParameter("startTime");
		        String endTime = request.getParameter("endTime");
		        map.put("startTime", startTime);
		        map.put("endTime", endTime);
		        
		        String startdateStr = (String) map.get("startTime");
				String enddateStr = (String) map.get("endTime");
				
				String statrt_endtime = "";
				if(startdateStr!=null || enddateStr!=null){
					
					DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
					long startTime_Long = df.parse(startdateStr).getTime();
					long endTime_Long = df.parse(enddateStr).getTime();
					
					DateFormat df1 = new SimpleDateFormat("yyyyMMdd");
					statrt_endtime = df1.format(new Date(startTime_Long))+"-"+df1.format(new Date(endTime_Long));
				}
		        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
		        List<TapesRecord> list = exportReportService.exportTapesRecord(map);
		        
		        if (null != list && !list.isEmpty()) {
		            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/tapse.xlsx").getPath();
		            
		            String destFileName = String.format("%s录音文件.xlsx", statrt_endtime);
		            Map<String, List<TapesRecord>> beanParams = new HashMap<String, List<TapesRecord>>();
		            beanParams.put("tapesList", list);
		
		            XLSTransformer transformer = new XLSTransformer();
		            InputStream in = null;
		            OutputStream out = null;
		            // 设置响应
		            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
		            response.setContentType("application/vnd.ms-excel");
		            try {
		                in = new BufferedInputStream(new FileInputStream(templateFileName));
		                Workbook workbook = transformer.transformXLS(in, beanParams);
		                out = response.getOutputStream();
		                // 将内容写入输出流并把缓存的内容全部发出去
		                workbook.write(out);
		                out.flush();
		            } finally {
		                if (in != null) {
		                    try {
		                        in.close();
		                    } catch (IOException e) {
		                    }
		                }
		                if (out != null) {
		                    try {
		                        out.close();
		                    } catch (IOException e) {
		                    }
		                }
		            }
		        } else {
		            response.setContentType("text/html;charset=UTF-8");
		            response.setCharacterEncoding("UTF-8");
		            response.getWriter().write("暂无数据");
		        }
				logger.info("导出录音文件数据成功");
			} catch (Exception e) {
				logger.error("导出录音文件数据失败",e);
				e.printStackTrace();
			}
	
	}
	
	
	
	/**
	 * 查询译员在线时长列表
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryTranslatorTimeList.web")
	public String queryTranslatorTimeList(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		return "/WEB-INF/jsp/systemmanage/exportreport/translatorOnlineList";
	}
	
	@RequestMapping(value = "/systemmanage/exportreport/queryTranslatorTimeDataGrid.json")
	public void queryTranslatorTimeDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());
			
			String startdateStr = (String) map.get("startTime");
			String enddateStr = (String) map.get("endTime");
			
			long resultCount = 0;
			List<TranslatorOnline> resultList=null;
			if(startdateStr!=null || enddateStr!=null){
				
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				
				long startTime = df.parse(startdateStr).getTime();
				map.put("startTime", startTime);
				long endTime = df.parse(enddateStr).getTime();
				map.put("endTime", endTime);
				ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
				resultCount = exportReportService.listTranslatorOnlineCount(map);
				resultList = exportReportService.listTranslatorOnline(map);
			}
			

			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("id", DataTypeConstant.STRING);
			dataStyle.addDepict("nick_name", DataTypeConstant.STRING);
			dataStyle.addDepict("phone", DataTypeConstant.STRING);
			dataStyle.addDepict("true_name",DataTypeConstant.STRING );
			dataStyle.addDepict("translator_type", DataTypeConstant.STRING);
			dataStyle.addDepict("lang_name_zh", DataTypeConstant.STRING);	 
			dataStyle.addDepict("ability", DataTypeConstant.STRING);	
			dataStyle.addDepict("daystr", DataTypeConstant.STRING);
			dataStyle.addDepict("duration", DataTypeConstant.STRING);
					
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载录音清单列表数据成功");
		} catch (Exception e) {
			logger.error("加载录音清单列表数据失败",e);
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value = "/systemmanage/exportreport/exportTranslatorTimeReport.web")
    public void exportTranslatorTimeReport(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		HashMap<String, Object> map = new HashMap<String, Object>();
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        
        String startdateStr = (String) map.get("startTime");
		String enddateStr = (String) map.get("endTime");
		
		if(startdateStr!=null || enddateStr!=null){
			
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			long startTime_Long = df.parse(startdateStr).getTime();
			map.put("startTime", startTime_Long);
			long endTime_Long = df.parse(enddateStr).getTime();
			map.put("endTime", endTime_Long);
			
		}
        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
        List<TranslatorOnline> list = exportReportService.listTranslatorOnlineTimeEpt(map);
        
        if (null != list && !list.isEmpty()) {
            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/translatortime.xlsx").getPath();
            String destFileName = String.format("译员每天在线时长_%s.xlsx", new DateTime().toString("yyyyMMddHHmmss"));
            Map<String, List<TranslatorOnline>> beanParams = new HashMap<String, List<TranslatorOnline>>();
            beanParams.put("timelineList", list);

            XLSTransformer transformer = new XLSTransformer();
            InputStream in = null;
            OutputStream out = null;
            // 设置响应
            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
            response.setContentType("application/vnd.ms-excel");
            try {
                in = new BufferedInputStream(new FileInputStream(templateFileName));
                Workbook workbook = transformer.transformXLS(in, beanParams);
                out = response.getOutputStream();
                // 将内容写入输出流并把缓存的内容全部发出去
                workbook.write(out);
                out.flush();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                    }
                }
            }
        } else {
            response.setContentType("text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write("暂无数据");
        }
    }
	
	
	
	/**
	 * 派单数据
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryTranslatorOrderList.web")
	public String queryTranslatorOrderList(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		return "/WEB-INF/jsp/systemmanage/exportreport/translatorOrderList";
	}
	
	@RequestMapping(value = "/systemmanage/exportreport/queryTranslatorOrderDataGrid.json")
	public void queryTranslatorOrderDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());
			
			String startdateStr = (String) map.get("startTime");
			String enddateStr = (String) map.get("endTime");
			
			long resultCount = 0;
			List<TranslatorOrder> resultList=null;
			if(startdateStr!=null || enddateStr!=null){
				
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				
				long startTime = df.parse(startdateStr).getTime();
				map.put("startTime", startTime);
				long endTime = df.parse(enddateStr).getTime();
				map.put("endTime", endTime);
				ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
				resultCount = exportReportService.listTranslatorOrderCount(map);
				resultList = exportReportService.listTranslatorOrder(map);
			}
			

			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("id", DataTypeConstant.STRING);
			dataStyle.addDepict("flow_id", DataTypeConstant.STRING);
			dataStyle.addDepict("truename",DataTypeConstant.STRING );
			dataStyle.addDepict("translatorid", DataTypeConstant.STRING);
			dataStyle.addDepict("processresult", DataTypeConstant.STRING);	 
			dataStyle.addDepict("optime", DataTypeConstant.STRING);	
					
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载派单列表数据成功");
		} catch (Exception e) {
			logger.error("加载派单列表数据失败",e);
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value = "/systemmanage/exportreport/exportTranslatorOrderReport.web")
    public void exportTranslatorOrderReport(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {

		try {
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
	        String startTime = request.getParameter("startTime");
	        String endTime = request.getParameter("endTime");
	        map.put("startTime", startTime);
	        map.put("endTime", endTime);
	        
	        String startdateStr = (String) map.get("startTime");
			String enddateStr = (String) map.get("endTime");
			
			String statrt_endtime = "";
			if(startdateStr!=null || enddateStr!=null){
				
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				long startTime_Long = df.parse(startdateStr).getTime();
				map.put("startTime", startTime_Long);
				long endTime_Long = df.parse(enddateStr).getTime();
				map.put("endTime", endTime_Long);
				
				DateFormat df1 = new SimpleDateFormat("yyyyMMdd");
				statrt_endtime = df1.format(new Date(startTime_Long))+"-"+df1.format(new Date(endTime_Long));
			}
	        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
	        List<TranslatorOrder> list = exportReportService.listTranslatorOrderEpt(map);
	        
	        if (null != list && !list.isEmpty()) {
	            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/translatororder.xlsx").getPath();
	            
	            String destFileName = String.format("%s派单数据.xlsx", statrt_endtime);
	            Map<String, List<TranslatorOrder>> beanParams = new HashMap<String, List<TranslatorOrder>>();
	            beanParams.put("translatororderList", list);

	            XLSTransformer transformer = new XLSTransformer();
	            InputStream in = null;
	            OutputStream out = null;
	            // 设置响应
	            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
	            response.setContentType("application/vnd.ms-excel");
	            try {
	                in = new BufferedInputStream(new FileInputStream(templateFileName));
	                Workbook workbook = transformer.transformXLS(in, beanParams);
	                out = response.getOutputStream();
	                // 将内容写入输出流并把缓存的内容全部发出去
	                workbook.write(out);
	                out.flush();
	            } finally {
	                if (in != null) {
	                    try {
	                        in.close();
	                    } catch (IOException e) {
	                    }
	                }
	                if (out != null) {
	                    try {
	                        out.close();
	                    } catch (IOException e) {
	                    }
	                }
	            }
	        } else {
	            response.setContentType("text/html;charset=UTF-8");
	            response.setCharacterEncoding("UTF-8");
	            response.getWriter().write("暂无数据");
	        }
			logger.info("导出派单列表数据成功");
		} catch (Exception e) {
			logger.error("导出派单列表数据失败",e);
			e.printStackTrace();
		}
    }
	
	
	/**
	 * 译员上下线时间点
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/systemmanage/exportreport/queryTranslatorOnOffList.web")
	public String queryTranslatorOnOff(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		return "/WEB-INF/jsp/systemmanage/exportreport/translatorOnOff";
	}
	
	@RequestMapping(value = "/systemmanage/exportreport/queryTranslatorOnOffDataGrid.json")
	public void queryTranslatorOnOffDataGrid(HttpServletRequest request, HttpServletResponse response, Model model) {
		PangingParam pangingParam = null;
		DataResult dataResult = new DataResult();
		DataGrid dataGrid = null;

		try {
			pangingParam = (PangingParam) ServletUtils.getParametersToBaseEntity(request, PangingParam.class);
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
			dataGrid = new DataGrid();
			dataGrid.setPangingParam(pangingParam);

			map.put("startrow", dataGrid.getStartrow());
			map.put("endrow", dataGrid.getEndrow());
			map.put("rows", dataGrid.getRows());
			map.put("sort", dataGrid.getSort());
			map.put("order", dataGrid.getOrder());
			
			String startdateStr = (String) map.get("startTime");
			String enddateStr = (String) map.get("endTime");
			
			long resultCount = 0;
			List<TranslatorOnOff> resultList=null;
			if(startdateStr!=null || enddateStr!=null){
				
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				
				long startTime = df.parse(startdateStr).getTime();
				map.put("startTime", startTime);
				long endTime = df.parse(enddateStr).getTime();
				map.put("endTime", endTime);
				ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
				resultCount = exportReportService.listTranslatorOnOffCount(map);
				resultList = exportReportService.listTranslatorOnOff(map);
			}
			
			DataStyle dataStyle = new DataStyle();
			dataStyle.setPageIndex(pangingParam.getPage());
			dataStyle.setDataCount(resultCount);
			dataStyle.setDataList(resultList);

			dataStyle.addDepict("translatorid", DataTypeConstant.STRING);
			dataStyle.addDepict("nick_name", DataTypeConstant.STRING);
			dataStyle.addDepict("phone",DataTypeConstant.STRING );
			dataStyle.addDepict("true_name", DataTypeConstant.STRING);
			dataStyle.addDepict("translator_type", DataTypeConstant.STRING);	 
			dataStyle.addDepict("lang_name_zh", DataTypeConstant.STRING);
			dataStyle.addDepict("ability", DataTypeConstant.STRING);
			dataStyle.addDepict("uptime", DataTypeConstant.STRING);
			dataStyle.addDepict("downtime", DataTypeConstant.STRING);
			
			dataResult = PangingTools.buildResultPagerInfo(dataStyle);

			if (pangingParam.getReportExportType() == 0) {
				response.getWriter().write(JSONFactory.toJSONString(dataResult, userContext));
			}
			logger.info("加载译员上下线列表数据成功");
		} catch (Exception e) {
			logger.error("加载译员上下线表数据失败",e);
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value = "/systemmanage/exportreport/exportTranslatorOnOffReport.web")
    public void exportTranslatorOnOffReport(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {

		try {
			HashMap<String, Object> map = (HashMap) ServletUtils.getParametersToHashMap(request);
	        String startTime = request.getParameter("startTime");
	        String endTime = request.getParameter("endTime");
	        map.put("startTime", startTime);
	        map.put("endTime", endTime);
	        
	        String startdateStr = (String) map.get("startTime");
			String enddateStr = (String) map.get("endTime");
			
			String statrt_endtime = "";
			if(startdateStr!=null || enddateStr!=null){
				
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				long startTime_Long = df.parse(startdateStr).getTime();
				map.put("startTime", startTime_Long);
				long endTime_Long = df.parse(enddateStr).getTime();
				map.put("endTime", endTime_Long);
				
				DateFormat df1 = new SimpleDateFormat("yyyyMMdd");
				statrt_endtime = df1.format(new Date(startTime_Long))+"-"+df1.format(new Date(endTime_Long));
			}
	        ExportReportService exportReportService = (ExportReportService) IssTransactionContainer.getInstance(ExportReportService.class, false);
	        List<TranslatorOnOff> list = exportReportService.listTranslatorOnOffEpt(map);
	        
	        if (null != list && !list.isEmpty()) {
	            String templateFileName = this.getClass().getClassLoader().getResource("excel_template/translatoronoff.xlsx").getPath();
	            
	            String destFileName = String.format("%s译员上下线时间点.xlsx", statrt_endtime);
	            Map<String, List<TranslatorOnOff>> beanParams = new HashMap<String, List<TranslatorOnOff>>();
	            beanParams.put("translatoronoffList", list);

	            XLSTransformer transformer = new XLSTransformer();
	            InputStream in = null;
	            OutputStream out = null;
	            // 设置响应
	            response.setHeader("Content-Disposition", "attachment;filename=" + new String((destFileName).getBytes("gbk"), "iso8859-1"));
	            response.setContentType("application/vnd.ms-excel");
	            try {
	                in = new BufferedInputStream(new FileInputStream(templateFileName));
	                Workbook workbook = transformer.transformXLS(in, beanParams);
	                out = response.getOutputStream();
	                // 将内容写入输出流并把缓存的内容全部发出去
	                workbook.write(out);
	                out.flush();
	            } finally {
	                if (in != null) {
	                    try {
	                        in.close();
	                    } catch (IOException e) {
	                    }
	                }
	                if (out != null) {
	                    try {
	                        out.close();
	                    } catch (IOException e) {
	                    }
	                }
	            }
	        } else {
	            response.setContentType("text/html;charset=UTF-8");
	            response.setCharacterEncoding("UTF-8");
	            response.getWriter().write("暂无数据");
	        }
			logger.info("导出译员上下线列表数据成功");
		} catch (Exception e) {
			logger.error("导出译员上下线列表数据失败",e);
			e.printStackTrace();
		}
    }
}
